package mortal.component.window
{
	import com.mui.controls.*;
	import flash.events.*;
	import flash.text.*;
	import mortal.component.gconst.*;
	import com.gengine.debug.*;
	
	public class DebugWindow extends BaseWindow implements ILog
	{
		private var _text:TextField;
		private var _clearBtn:GButton;
		private var _textStr:String = "";
		private static var _instance:DebugWindow;
		
		public function DebugWindow()
		{
			if (_instance)
			{
				throw new Error("DebugWindow 单例");
			}
			this.setSize(400, 500);
			
		}
		
		override protected function createChildren() : void
		{
			super.createChildren();
			this._text = new TextField();
			this._text.type = TextFieldType.DYNAMIC;
			this._text.selectable = true;
			this._text.defaultTextFormat = StyleConst.textFormatA;
			this.addChild(this._text);
			this._clearBtn = new GButton();
			this._clearBtn.label = "清除内容";
			this._clearBtn.addEventListener(MouseEvent.CLICK, this.onClickHandler);
			this.addChild(this._clearBtn);
			
		}
		
		override protected function updateSize() : void
		{
			super.updateSize();
			this._text.height = _windowCenter.height - 20;
			this._text.width = _windowCenter.width - 20;
			this._text.x = _windowCenter.x + 10;
			this._text.y = _windowCenter.y + 10;
			this._clearBtn.y = titleHeight - this._clearBtn.height + 4;
			this._clearBtn.x = this._text.x + this._text.width - this._clearBtn.width;
			
		}
		
		private function onClickHandler(event:MouseEvent) : void
		{
			this._textStr = "";
			this._text.text = "";
			
		}
		
		public function print(param1:Object) : void
		{
			this._textStr = this._textStr + (param1.toString() + "\n");
			if (this.parent)
			{
				this._text.text = this._textStr;
				this._text.scrollV = this._text.maxScrollV;
			}
			
		}
		
		public static function get instance() : DebugWindow
		{
			if (_instance == null)
			{
				_instance = new DebugWindow;
			}
			return _instance;
		}
		
	}
}
